There are several control statements available in C. They are; 'while', 'for', 'do', 'if', conditional, 'switch', and the infamous 'goto'. Syntax for these statements are:
while( expr )
statement
for( init; test; update )
statement
do // statement executed at least once
statement
while( expr );
if( expr )
statement
else if( expr )
statement
else
statement
expr ? expr : expr // conditional
switch( expr )
{
case const1: statement
break; // without break, control
case const2: statement // continues to next
break; // statement.
case const3: statement
break;
default : statement
}
goto label;
.
.
.
label:statement
FLOW CONTROL EXAMPLES
The following program provides some basic examples of each control statement. One of the more common typos is to use commas instead of semi-colons in 'for' statements. Although the goto statement is provided in C, it is usually avoided and most books advise against its use. The conditional statement is shorthand for an if-then statement, but it can decrease code readability (mainly because it is rarely used).